<script>
	function MyScoreCtrl($scope, CtrlUtil, $element, modalService, $http, UploadService, toaster) {
		var ctrl = this
		this.onQuerySuccess = function (c) {
			return $http.post(':root/score/getApply', { term: ctrl.current.term.id }).success(function (R) {
				ctrl.apply = R
			})
		}
		CtrlUtil.build(this, ':root/score/getMyScore')
		this.modal = function (config) {
			var content = $element.find('[template]>[' + config.template + ']').clone();
			var btn = content.find('[file]')
			var result = config.result || {}
			if (btn.length > 0) {
				var uploadConfig = {
					multipleFiles: false,
					autoUploading: true,
					maxSize: 1024 * 1024 * 2,
					onAddTask: function (file, dat) {
						result.fileName = file.name;
						$scope.$$phase || $scope.$apply()
					},
					extFilters: [".jpg", ".jpeg", ".png", ".gif", ".bmp"],
					onComplete: function (file) {
						var attach = {}
						attach.fileName = file.name;
						attach.hash = eval('(' + file.msg + ')').message;
						attach.size = file.size;
						attach.uploading = false
						result.fjId = (attach.hash + '/' + attach.size)
						result.fileName = file.name;
						result.filePercent = '100%'
						result.imageUrl = UploadService.getServerUrl() + '/preview/getImage?w=280&h=170&hash=' + attach.hash + '&size='
							+ attach.size
						$scope.$$phase || $scope.$apply()
					},
					onMaxSizeExceed: function (file) {
						toaster.pop({
							type: 'error',
							body: '文件大小不能超过2M',
							timeout: 800
						});
						$scope.$$phase || $scope.$apply()
					},
					onExtNameMismatch: function (file) {
						toaster.pop({
							type: 'error',
							body: '只能选择图片文件',
							timeout: 800
						});
						$scope.$$phase || $scope.$apply()
					},
					onUploadProgress: function (param) {
						result.filePercent = param.percent + '%;'
						$scope.$$phase || $scope.$apply()
					}
				}
				setTimeout(function () {
					uploadConfig.browser = content.find('[file]')[0]
					var stream = UploadService.create(uploadConfig)
				})
			}
			var applied = ctrl.apply[config.template]
			var method = applied ? 'show' : 'confirm'
			return modalService[method]({
				title: config.title,
				content: content,
				result: applied || result,
				applied: applied,
				ctrl: ctrl,
				validator: function (r) {
					if (!r.fjId) {
						toaster.pop({
							type: 'error',
							body: '请上传附件',
							timeout: 800
						});
						$scope.$$phase || $scope.$apply()
						return false;
					}
				}
			}, {
					backdrop: !!applied
				})
		}
		this.suspend = function () {
			ctrl.modal({
				title: '申请保留成绩',
				template: 'suspend'
			}).then(function (r) {
				r.stuInfo = ctrl.current
				$http.post(':root/score/applySuspend', r).success(function (R) {
					if (R) {
						modalService.succ('申请发送成功', 1500)
					}
				})
			})
		}
		this.continuing = function () {
			ctrl.modal({
				title: '申请续修课程',
				template: 'continue'
			}).then(function (r) {
				r.stuInfo = ctrl.current
				$http.post(':root/score/continueApply', r).success(function (R) {
					if (R) {
						modalService.succ('申请发送成功', 1500)
					}
				})
			})
		}
		this.cert = function () {
			ctrl.modal({
				title: '结业证书补办',
				template: 'cert'
			}).then(function (r) {
				r.stuInfo = ctrl.current
				$http.post(':root/score/reApplyCert', r).success(function (R) {
					if (R) {
						modalService.succ('申请发送成功', 1500)
					}
				})
			})
		}
		this.toImageUrl = CtrlUtil.toImageUrl
		this.onStuLoad = function (data) {
			this.changeStu(data[0])
		}
		this.changeStu = function (stu) {
			this.current = stu
			this.termQueryParam = this.current && this.current.term.id
			this.entities = null
			this.query()
		}
	}

</script>
<div ng-controller="MyScoreCtrl as ctrl">
	<h3 class="header container-fluid media">我的成绩</h3>
	<div class="container-fluid">
		<div class="well h4 ">
			<label>一份耕耘，一份收获！</label>
		</div>
	</div>
	<data entity="StuInfo" page="false" auto-load="true" after-refresh="stuInfo=data;ctrl.onStuLoad(data)">
		<filter field="user.id" value="$root.$user.id"></filter>
	</data>
	<div class="container-fluid media">
		<div class="row media">
			<ul class="nav nav-tabs">
				<li role="presentation" ng-click="ctrl.changeStu(s)" ng-repeat="s in stuInfo" ng-class="{active:ctrl.current==s}"><a href="javascript:;">{{s.term.name+s.term.trainType.name}}</a></li>
			</ul>
		</div>
		<div class="row media">
			<div class="col-md-6"></div>
			<div class="col-md-6"></div>
		</div>
		<table class="table table-striped table-hover table-bordered text-center media" ng-show="ctrl.current">
			<!-- 	<tr>
				<th class="text-center" colspan="3">平时考勤成绩</th>
				<th class="text-center" colspan="3">结业考试</th>
			</tr>
			<tr class="text-center">
				<th class="text-center">必修课</th>
				<th class="text-center">选修课</th>
				<th class="text-center">体验课</th>
				<th class="text-center">选择题</th>
				<th class="text-center">主观题</th>
				<th class="text-center">总计</th>
			</tr>
			<tr>
				<td>{{ctrl.entities.bxk|nullText}}</td>
				<td>{{ctrl.entities.xxk|nullText}}</td>
				<td>{{ctrl.entities.tyk|nullText}}</td>
				<td>{{ctrl.entities.xzt|nullText}}</td>
				<td>{{ctrl.entities.zgt|nullText}}</td>
				<td>{{ctrl.entities.zj|nullText}}</td>
			</tr> -->
			<tr>
				<td width="50%">考核结果：</td>
				<td width="50%">{{ctrl.entities.khjg|nullText}}</td>
			</tr>

		</table>
	</div>
	<div class="container-fluid media text-center" ng-show="ctrl.current">
		<div class="col-md-8 col-md-offset-2">
			<div class="col-xs-4">
				<a class="btn btn-cys" ng-click="ctrl.suspend()">申请保留成绩</a>
			</div>
			<div class="col-xs-4">
				<a class="btn btn-cys" ng-click="ctrl.continuing()">申请续修课程</a>
			</div>
			<div class="col-xs-4">
				<a class="btn btn-cys" ng-click="ctrl.cert()">下载结业证</a>
			</div>
		</div>
	</div>
	<div ng-non-bindable template class="hidden">
		<div suspend>
			<form>
				<div class="form-group">
					<label for="exampleInputEmail1">保留期限</label>
					<input ng-disabled="applied" ng-model="result.blqx" type="text" required="required" class="form-control" name="blqx" placeholder="保留期限">
				</div>
				<div class="form-group">
					<label for="exampleInputPassword1">申请原因</label>
					<textarea ng-disabled="applied" rows="3" ng-model="result.sqyy" style="resize: none;" required="required" name="reason" class="form-control"
					 placeholder="申请原因">
					</textarea>
				</div>
				<div class="form-group" ng-if="applied">
					<label for="exampleInputEmail1">状态</label>
					<span ng-disabled="applied" ng-bind="result.status|auditString" type="text" class="form-control" name="status"></span>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="!applied">
					<p>上传证明材料</p>
					<p>【提醒】： 证明材料必须要上传哦，上传图片格式，且大小不要超过2M。</p>
					<p>{{result.fileName}}</p>
					<div ng-show="result.filePercent" class="progress">
						<div class="progress-bar progress-bar-success" role="progressbar" aria-valuemin="0" aria-valuemax="100" ng-style="{width: result.filePercent}">
							<span ng-show="result.filePercent=='100%'" class="pull-right glyphicon glyphicon-ok"></span>
						</div>

					</div>
					<div file id="suspend-file" class="btn btn-cys col-md-6">上传证明材料</div>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="applied">
					<p>证明材料</p>
					<p>
						<a ng-href="{{ctrl.toImageUrl(result.fjId)}}" target="_blank">
							<img class="img-responsive" ng-src="{{ctrl.toImageUrl(result.fjId)}}">
						</a>
					</p>
				</div>
			</form>
		</div>
		<div continue>
			<form>
				<div class="form-group">
					<label for="exampleInputPassword1">申请原因</label>
					<textarea ng-disabled="applied" rows="3" ng-model="result.sqyy" style="resize: none;" required="required" name="reason" class="form-control"
					 placeholder="申请原因">
					</textarea>
				</div>
				<div class="form-group" ng-if="applied">
					<label for="exampleInputEmail1">状态</label>
					<span ng-disabled="applied" ng-bind="result.status|auditString" type="text" class="form-control" name="status"></span>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="!applied">
					<p>上传证明材料</p>
					<p>【提醒】： 证明材料必须要上传哦，上传图片格式，且大小不要超过2M。</p>
					<p>{{result.fileName}}</p>
					<div ng-show="result.filePercent" class="progress">
						<div class="progress-bar progress-bar-success" role="progressbar" aria-valuemin="0" aria-valuemax="100" ng-style="{width: result.filePercent}">
							<span ng-show="result.filePercent=='100%'" class="pull-right glyphicon glyphicon-ok"></span>
						</div>

					</div>
					<div file id="continue-file" class="btn btn-cys col-md-6">上传证明材料</div>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="applied">
					<p>证明材料</p>
					<p>
						<a ng-href="{{ctrl.toImageUrl(result.fjId)}}" target="_blank">
							<img class="img-responsive" ng-src="{{ctrl.toImageUrl(result.fjId)}}">
						</a>
					</p>
				</div>
			</form>
		</div>
		<div cert>
			<form>
				<div class="form-group">
					<label for="exampleInputPassword1">补办原因</label>
					<textarea ng-disabled="applied" rows="3" ng-model="result.sqyy" style="resize: none;" required="required" name="reason" class="form-control"
					 placeholder="补办原因">
					</textarea>
				</div>
				<div class="form-group" ng-if="applied">
					<label for="exampleInputEmail1">状态</label>
					<span ng-disabled="applied" ng-bind="result.status|auditString" type="text" class="form-control" name="status"></span>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="!applied">
					<p>上传证明材料</p>
					<p>【提醒】： 证明材料必须要上传哦，上传图片格式，且大小不要超过2M。</p>
					<p>{{result.fileName}}</p>
					<div ng-show="result.filePercent" class="progress">
						<div class="progress-bar progress-bar-success" role="progressbar" aria-valuemin="0" aria-valuemax="100" ng-style="{width: result.filePercent}">
							<span ng-show="result.filePercent=='100%'" class="pull-right glyphicon glyphicon-ok"></span>
						</div>

					</div>
					<div file id="cert-file" class="btn btn-cys col-md-6">上传证明材料</div>
				</div>
				<div class="thumbnail form-group col-md-12" ng-if="applied">
					<p>证明材料</p>
					<p>
						<a ng-href="{{ctrl.toImageUrl(result.fjId)}}" target="_blank">
							<img class="img-responsive" ng-src="{{ctrl.toImageUrl(result.fjId)}}">
						</a>
					</p>
				</div>
			</form>
		</div>
	</div>
</div>